|
|
|
|
|
|
|
Initializing the TreeView control really has nothing to do with data access; however, it's required before adding any entry names. The code in Listing 10.8 sets the TreeView control. For each added node, the associated letter is used as the key, allowing you to access that node directly later in the process. |
|
|
|
|
|
|
|
|
LISTING 10.8. ADDRDAO1.TXTINITIALIZING THE TREEVIEW CONTROL AT THE START OF THE APPLICATION. |
|
|
|
 |
|
|
|
|
1: Public Sub Set_NewTree()
2: Dim Node_Letter As String * 1
3: tvTreeView.Nodes.Clear
4: Set MyNode = tvTreeView.Nodes.Add(, , AB, Address Book, 1)
5: For I = 1 To 26
6: Node_Letter = Mid(ABCDEFGHIJKLMNOPQRSTUVWXYZ, I, 1)
7: Set MyNode = tvTreeView.Nodes.Add(AB, tvwChild, Node_Letter, _
8: Node_Letter, 2)
9: Next I
10: End Sub |
|
|
|
|
|
|
|
|
Note Don't forget that the TreeView needs an Image control if you want the different nodes to have pictures associated with them. |
|
|
|
|
|
|
|
|
|
Now that you have the TreeView control ready to accept data, you can create the code needed to perform this action. To add the entry names as shown in Figure 10.13, you need to perform the following actions: |
|
|
|
|
|
|
|
|
1. Open a database connection. |
|
|
|
|
|
|
|
|
2. Open a Recordset by using a SQL statement. |
|
|
|
|
|
|
|
|
3. Loop through records, adding the name to the TreeView control by using the first letter of the last name as the key to the current node. |
|
|
|
|
|
|
|
|
For this application, add the last name followed by the first name to the list. Also, the key to each item will be the AddressID and the last name as one string field, to provide a unique key for each node. It will also allow you to access the AddressID later in the application to display an entry. |
|
|
|
|
|
|
|
|
The code in Listing 10.9 can be placed in the Form_Load routine for the application so that the TreeView control is initialized when the application is started. However, if you're allowing users to select an address book database to use, and there might be several different ones, you should place this initialization code into a separate subroutine that can be called when needed. |
|
|
|
|
|